<div class="title">Thex-Assembly Examples</div>
<ul>
    <li><a href="#examples-1">第一个程序：Hello</a></li>
    <li>数值计算</li>
    <ul>
        <li><a href="#examples-2-1">整数运算</a></li>
        <li><a href="#examples-2-2">实数运算</a></li>
    </ul>
</ul>

<div class="part"><pre id="examples-1">
# The Hello Program

# Define static-data section, All memory of this section is Readonly
section const
    # Declare an memory block, 'message' is Address alias of this memory block, string in back is initialize values of this memory block.
    # Because it's simple style of Declare syntax, So by Compile to alloc address and manage.
    message = "Hello Thex-Assembly"
end

# Define an function, The 'main' is program entry function
main
    # Call function('.' prefix is internal Functions of Thexasm), let arguments by letf-right order assign to Universally-Registers
    # Same:
    #   a := message
    #   (.println)
    # This function write a line to Standard-Output Device
    (.println message)
end
# Output:
# Hello Thex-Assembly
</pre></div>

<div class="part"><pre id="examples-2-1">
# Integer Arithmtic
section const
    # Declare an 64byte memory block, Use 0x0 as initialize values
    display:64 = 0
end
main
    # Copy Integer to Registers
    a := 1
    b := 2
    # Copy A+B result to C
    c := a+b
    # Simple style of:
    #   push c
    #   push b
    #   push a
    pushr a b c
    # Same:
    #   const FORMAT_1 "a={1}, b={2}, c={3}"
    #   pushr a b c
    #   (.format display FORMAT_1 3)
    #   (.println display)
    (.fprintln display "a={1}, b={2}, c={3}" 3)
end
# Output:
# a=1, b=2, c=3
</pre></div>

<div class="part"><pre id="examples-">
# Memory I/O
section var
    ma:4 = 0
end
load
    r := [a]
end
save
    [a] := b
end
main
    (load ma)  # Load memory to registers
    b := 1
    (save ma)  # [n] now is 0x00000001
    (load ma)
    b := r+1
    (save ma)  # [n] now is 0x00000002
end
</pre></div>

